import { Action } from "@ngrx/store";
import { Layer } from "../../class";
import { FeaturePropertyType } from "../../models/layer.model";
import { QueryRuleResult } from "../../components/properties-query";


export enum LayersActionTypes {
    INITIAL_LAYERS = '[Layers] Initial Layer!',
    INITIAL_LAYERS_FAIL = '[Layers] Initial Layer Fail!',
    INITIAL_LAYERS_SUCCESS = '[Layers] Initial Layer Success!',
    LOAD_LAYER = '[Layers] Load Layer!',
    LOAD_LAYER_FAIL = '[Layers] Load Layer Fail!',
    LOAD_LAYER_SUCCESS = '[Layers] Load Layer Success!',
    REMOVE_LAYER = '[Layers] Remove Layer!',
    LAYERS_SORT = '[Layers] Layers Sort!',
    LAYERS_CLEAN = '[Layers] Layers Clean!',
    LAYER_VISIBLE = '[Layers] Layer Visible!',
    LAYER_INVISIBLE = '[Layers] Layer Invisible!',
    LAYER_OPACITY = '[Layers] Layer Opacity!',
    LAYERS_SPATIAL_QUERY_USEABLE = '[Layers] Layers Spatial Query Useable!',
    LAYERS_SPATIAL_QUERY_UnuSEABLE = '[Layers] Layers Spatial Query Unuseable!',
    LAYER_ADD_TABLE = '[Layers] Layer Add Table!',
    LAYER_REMOVE_TABLE = '[Layers] Layer Remove Table!',
    LAYER_TABLE_VISIBLE = '[Layers] Layer Table Visible!',
    LAYER_TABLE_HIDDEN = '[Layers] Layer Table Hidden!',
    LAYER_TABLE_REMOVED = '[Layers] Layer Table Removed!',
    LAYER_SOURCE_LOADING = '[Layers] Layer Source Loading!',
    LAYER_SOURCE_LOADED = '[Layers] Layer Source Loaded!',
    LAYER_SOURCE_LOADERROR = '[Layers] Layer Source Load Error!',
    LAYER_FEATURE_SELECTED = '[Layers] Layer Feature Selected!',
    LAYER_FEATURE_DESELECTED = '[Layers] Layer Feature Deselected!',
    LAYER_ADD_QUERY_RESULT = '[Layers] Layer Add Query Result!',
    LAYER_REMOVE_QUERY_RESULT = '[Layers] Layer Remove Query Result!',
    LAYER_FIELD_TYPES = '[Layers] Layer Field Types!',
}

export class InitialLayers implements Action {
    readonly type = LayersActionTypes.INITIAL_LAYERS;
}

export class InitialLayersFail implements Action {
    readonly type = LayersActionTypes.INITIAL_LAYERS_FAIL;
    constructor(public payload: any) {}
}

export class InitialLayersSuccess implements Action {
    readonly type = LayersActionTypes.INITIAL_LAYERS_SUCCESS; 
    constructor(public payload: Layer[]) {}
}

export class LoadLayer implements Action {
    readonly type = LayersActionTypes.LOAD_LAYER;
    constructor(public payload: string[]) {}
}

export class LoadLayerFail implements Action {
    readonly type = LayersActionTypes.LOAD_LAYER_FAIL;
    constructor(public payload: any) {}
}

export class LoadLayerSuccess implements Action {
    readonly type = LayersActionTypes.LOAD_LAYER_SUCCESS;
    constructor(public payload: Layer[]) {}
}


export class RemoveLayer implements Action {
    readonly type = LayersActionTypes.REMOVE_LAYER;
    constructor(public payload: string) {}
}

export class LayersSort implements Action {
    readonly type = LayersActionTypes.LAYERS_SORT;
    constructor(public payload: string[]) {}
}

export class LayersClean implements Action {
    readonly type = LayersActionTypes.LAYERS_CLEAN;
}

export class LayerVisible implements Action {
    readonly type = LayersActionTypes.LAYER_VISIBLE;
    constructor(public payload: string) {}
}

export class LayerInvisible implements Action {
    readonly type = LayersActionTypes.LAYER_INVISIBLE;
    constructor(public payload: string) {}
}

export class LayerOpacity implements Action {
    readonly type = LayersActionTypes.LAYER_OPACITY;
    constructor(public payload: { id: string, opacity: number }) {}
}

export class LayersSpatialQueryUseable implements Action {
    readonly type = LayersActionTypes.LAYERS_SPATIAL_QUERY_USEABLE;
}

export class LayersSpatialQueryUnuseable implements Action {
    readonly type = LayersActionTypes.LAYERS_SPATIAL_QUERY_UnuSEABLE;
}

export class LayerAddTable implements Action {
    readonly type = LayersActionTypes.LAYER_ADD_TABLE;
    constructor(public payload: string) {}
}

export class LayerRemoveTable implements Action {
    readonly type = LayersActionTypes.LAYER_REMOVE_TABLE;
    constructor(public payload: string) {}
}

export class LayerTableHidden implements Action {
    readonly type = LayersActionTypes.LAYER_TABLE_HIDDEN;
}

export class LayerTableRemoved implements Action {
    readonly type = LayersActionTypes.LAYER_TABLE_REMOVED;
}

export class LayerTableVisible implements Action {
    readonly type = LayersActionTypes.LAYER_TABLE_VISIBLE;
}

export class LayerSourceLoaded implements Action {
    readonly type = LayersActionTypes.LAYER_SOURCE_LOADED;
    constructor(public payload: { id: string, data: { [key: string]: any }[]}) {}
}

export class LayerSourceLoading implements Action {
    readonly type = LayersActionTypes.LAYER_SOURCE_LOADING;
    constructor(public payload: string) {}
}

export class LayerSourceLoadError implements Action {
    readonly type = LayersActionTypes.LAYER_SOURCE_LOADERROR;
    constructor(public payload: { id: string, error: any }) {}
}

export class LayerFeatureSelected implements Action {
    readonly type = LayersActionTypes.LAYER_FEATURE_SELECTED;
    constructor(public payload: { layerId: string, featureId: string }) {}
}

export class LayerFeatureDeselected implements Action {
    readonly type = LayersActionTypes.LAYER_FEATURE_DESELECTED;
    constructor(public payload: { layerId: string, featureId: string }) {}
}

export class LayerAddQueryResult implements Action {
    readonly type = LayersActionTypes.LAYER_ADD_QUERY_RESULT;
    constructor(public payload: { id: string, result: { [key: string]: any }[] }) {}
}

export class LayerRemoveQueryResult implements Action {
    readonly type = LayersActionTypes.LAYER_REMOVE_QUERY_RESULT;
    constructor(public payload: string) {}
}

export class LayerFieldTypes implements Action {
    readonly type = LayersActionTypes.LAYER_FIELD_TYPES;
    constructor(public payload: { id: string, fieldTypes: FeaturePropertyType[] }) {}
}

export type LayersAction
    = InitialLayers
    | InitialLayersFail
    | InitialLayersSuccess
    | LoadLayer
    | LoadLayerFail
    | LoadLayerSuccess
    | RemoveLayer
    | LayersSort
    | LayersClean
    | LayerInvisible
    | LayerVisible
    | LayerOpacity
    | LayersSpatialQueryUseable
    | LayersSpatialQueryUnuseable
    | LayerAddTable
    | LayerRemoveTable
    | LayerTableHidden
    | LayerTableRemoved
    | LayerTableVisible
    | LayerSourceLoaded
    | LayerSourceLoadError
    | LayerSourceLoading
    | LayerFeatureDeselected
    | LayerFeatureSelected
    | LayerAddQueryResult
    | LayerRemoveQueryResult
    | LayerFieldTypes;

